﻿/**  版本信息模板在安装目录下，可自行修改。
* Bas_Menus.cs
*
* 功 能： N/A
* 类 名： Bas_Menus
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2014/3/18 14:45:58   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using DBHelper;
using SME.Food.Surperise.Model;

namespace SME.Food.Surperise.DAL
{
	/// <summary>
	/// 数据访问类:Bas_Menus
	/// </summary>
	public partial class Bas_Menus_DAL
	{
        public Bas_Menus_DAL()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("Menus_No", "Bas_Menus"); 
		}


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from Bas_Menus");
			strSql.Append(" where ID="+ID+" ");
			return DbHelperSQL.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
        public int Add(Bas_Menus_Model model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.Menus_No != null)
			{
				strSql1.Append("Menus_No,");
				strSql2.Append("'"+model.Menus_No+"',");
			}
			if (Int32.Parse(model.TotalNum.ToString()) >0)
			{
				strSql1.Append("TotalNum,");
				strSql2.Append(model.TotalNum+",");
			}
			if (model.TotalMony >0)
			{
				strSql1.Append("TotalMony,");
				strSql2.Append(""+model.TotalMony+",");
			}
			if (model.Menus_Statue >=0)
			{
				strSql1.Append("Menus_Statue,");
				strSql2.Append(""+model.Menus_Statue+",");
			}
		    strSql1.Append("Menus_Time,");
		    strSql2.Append("'"+model.Menus_Time+"',");

		    if (model.Mem_No != null)
			{
				strSql1.Append("Mem_No,");
				strSql2.Append("'"+model.Mem_No+"',");
			}
		   
		    if (model.Remark != null)
			{
                strSql1.Append("Remark,");
                strSql2.Append("'" + model.Remark + "',");
			}

		    strSql.Append("insert into Bas_Menus(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			strSql.Append(";select @@IDENTITY");
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}


       

	    /// <summary>
		/// 更新一条数据
		/// </summary>
        public bool Update(Bas_Menus_Model model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Bas_Menus set ");
			if (model.Menus_No != null)
			{
				strSql.Append("Menus_No='"+model.Menus_No+"',");
			}
            if (Int32.Parse(model.TotalNum.ToString()) > 0)
			{
				strSql.Append("TotalNum="+model.TotalNum+",");
			}
			if (model.TotalMony>0)
			{
				strSql.Append("TotalMony="+model.TotalMony+",");
			}
			if (model.Menus_Statue>0)
			{
				strSql.Append("Menus_Statue="+model.Menus_Statue+",");
			}
			if (model.Mem_No != null)
			{
				strSql.Append("Mem_No='"+model.Mem_No+"',");
			}
           if (model.Remark != null)
			{
                strSql.Append("Remark='" + model.Remark + "',");
			}
			int n = strSql.ToString().LastIndexOf(",", System.StringComparison.Ordinal);
			strSql.Remove(n, 1);
			strSql.Append(" where ID="+ model.ID+"");
            int rowsAffected = DbHelperSQL.ExcuteNoQuery(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
        public bool Delete(string Menus_No)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Bas_Menus ");
            strSql.Append(" where Menus_No=" + Menus_No + "");
            int rowsAffected = DbHelperSQL.ExcuteNoQuery(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Bas_Menus ");
            strSql.Append(" where Menus_No in (" + IDlist + ")  ");
            int rows = DbHelperSQL.ExcuteNoQuery(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public Bas_Menus_Model GetModel(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
            strSql.Append(" ID,Menus_No,TotalNum,TotalMony,Menus_Statue,Menus_Time,Mem_No,Remark ");
			strSql.Append(" from Bas_Menus ");
            strSql.Append(" where Menus_No=" + ID + "");
            Bas_Menus_Model model = new Bas_Menus_Model();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public Bas_Menus_Model DataRowToModel(DataRow row)
		{
            Bas_Menus_Model model = new Bas_Menus_Model();
			if (row != null)
			{
				if(row["ID"]!=null && row["ID"].ToString()!="")
				{
					model.ID=int.Parse(row["ID"].ToString());
				}
				if(row["Menus_No"]!=null)
				{
					model.Menus_No=row["Menus_No"].ToString();
				}
				if(Int32.Parse(row["TotalNum"].ToString())>0)
				{
					model.TotalNum=Int32.Parse(row["TotalNum"].ToString());
				}
				if(row["TotalMony"]!=null && row["TotalMony"].ToString()!="")
				{
					model.TotalMony=decimal.Parse(row["TotalMony"].ToString());
				}
				if(row["Menus_Statue"]!=null && row["Menus_Statue"].ToString()!="")
				{
					model.Menus_Statue=int.Parse(row["Menus_Statue"].ToString());
				}
				if(row["Menus_Time"]!=null && row["Menus_Time"].ToString()!="")
				{
					model.Menus_Time=DateTime.Parse(row["Menus_Time"].ToString());
				}
                if (row["Remark"] != null && row["Remark"].ToString() != "")
				{
                    model.Remark = row["Remark"].ToString();
				}
                
				if(row["Mem_No"]!=null)
				{
					model.Mem_No=row["Mem_No"].ToString();
				}

			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select ID,Menus_No,TotalNum,TotalMony,Menus_Statue,Menus_Time,Mem_No ,Remark");
			strSql.Append(" FROM Bas_Menus ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM Bas_Menus ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

